/**
 * Copyright (c) 2013-5-3 下午5:03:32 WKM and/or its affiliates. 
 * Use is subject to license terms.
 * All rights reserved.
 */
package org.extblog.wkm.web.service.upload.impl;

import java.util.Calendar;

import javax.annotation.Resource;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.extblog.wkm.web.dao.upload.FileUploadDao;
import org.extblog.wkm.web.service.AbstractService;
import org.extblog.wkm.web.service.upload.FileUploadService;
import org.extblog.wkm.web.util.DateFormatPattern;
import org.extblog.wkm.web.vo.FileUploadView;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author WKM
 * Service.java history
 * 1.WKM - 2013-5-3 - Create File
 */
@Controller
public class FileUploadServiceImpl extends AbstractService implements
		FileUploadService {
	
	private FileUploadDao fileUploadDao = null;

	public FileUploadDao getFileUploadDao() {
		return fileUploadDao;
	}

	@Resource
	public void setFileUploadDao(FileUploadDao fileUploadDao) {
		this.fileUploadDao = fileUploadDao;
	}

	/* (non-Javadoc)
	 * @see org.extblog.wkm.web.service.music.FileUploadService#addFile(org.springframework.web.multipart.MultipartFile)
	 */
	@Override
	public boolean addFile(MultipartFile fileContent) {
		// TODO Auto-generated method stub
		FileUploadView view = new FileUploadView();
		view.setFileId(DateFormatPattern.ID + DateFormatPattern.SPLIT_CHAR + DateFormatUtils.format(Calendar.getInstance(),DateFormatPattern.DATE_TIME));
		log.info("存储文件:" + fileContent.getName());
		log.info("存储文件ID:" + view.getFileId());
		int count = fileUploadDao.insertMusic(fileContent, view);
		log.info("影响数据个数:" + count);
		return count >= 0;
	}

}
